<!DOCTYPE html>
<html lang="zh-cn">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>{$CONF['mallTitle']}后台管理中心</title>
      <link href="__PUBLIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="__ROOT__/Apps/Admin/View/css/AdminLTE.css" rel="stylesheet" type="text/css" />
      <link href="__ROOT__/Apps/Admin/View/css/upload.css" rel="stylesheet" type="text/css" />
      <link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/webuploader/webuploader.css" />
      <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.min.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
      <![endif]-->
      <script src="__PUBLIC__/js/jquery.min.js"></script>
      <script src="__PUBLIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
      <script src="__PUBLIC__/js/common.js"></script>
      <script src="__PUBLIC__/plugins/plugins/plugins.js"></script>
      <script src="__PUBLIC__/plugins/formValidator/formValidator-4.1.3.js"></script>
      <script type="text/javascript" src="__ROOT__/Apps/Admin/View/js/upload.js"></script>
      <script type="text/javascript" src="__PUBLIC__/plugins/webuploader/webuploader.js"></script>
      <script src="__PUBLIC__/plugins/layer/layer.min.js"></script>
   </head>
   <script>
   var ThinkPHP = window.Think = {
          "DOMAIN" : "{:WSTDomain()}"
  };
   $(function () {
	   $.formValidator.initConfig({
		   theme:'Default',mode:'AutoTip',formID:"myform",debug:true,submitOnce:true,onSuccess:function(){
				   edit();
			       return false;
			},onError:function(msg){
		}});
     $("#keyword").formValidator({onShow:"",onFocus:"关键字至少要输入1个字符",onCorrect:"输入正确"}).inputValidator({min:1,max:20,onError:"你输入的长度不正确,请确认"});
     $("#title").formValidator({onShow:"",onFocus:"标题至少要输入1个字符",onCorrect:"输入正确"}).inputValidator({min:1,max:20,onError:"你输入的长度不正确,请确认"});
     $("#description").formValidator({onShow:"",onFocus:"描述至少要输入1个字符",onCorrect:"输入正确"}).inputValidator({min:1,max:56,onError:"你输入的长度不正确,请确认"});
     $("#url").formValidator({onShow:"",onFocus:"请输入图文链接",onCorrect:"输入正确"}).inputValidator({min:1,max:200,onError:"你输入的长度不正确,请确认"});
     $("#picUrl").formValidator({onShow:"",onFocus:"请上传封面图片",onCorrect:"输入正确"}).inputValidator({min:1,max:200,onError:"请上传封面图片"});
	   $("#content").formValidator({onShow:"",onFocus:"回复内容至少要输入1个字符",onCorrect:"输入正确"}).inputValidator({min:1,max:300,onError:"你输入的长度不正确,请确认"});
	   

     /*上传图片*/
    var uploading = null;
    uploadFile({
          server:"{:U('Admin/WxPassiveReply/uploadPic')}",
          pick:'#filePicker',
          formData: {dir:'wechat'},
          callback:function(f){
            layer.close(uploading);
            var json = WST.toJson(f);
            $('#preview').attr('src',ThinkPHP.DOMAIN+"/"+json.file.savepath+json.file.savethumbname);
            $('#picUrl').val(ThinkPHP.DOMAIN+'/'+json.file.savepath+json.file.savename);
            $('#preview').show();
          },
          progress:function(rate){
           uploading = WST.msg('正在上传图片，请稍后...');
          }
      });

   });
   function edit(){
	   var params = {};
     if($('#id').val()>0)params.id = $('#id').val();
     params.keyword = $('#keyword').val();
     params.title = $('#title').val();
     params.description = $('#description').val();
     params.picUrl = $('#picUrl').val();
     params.url = $('#url').val();
	   params.content = $('#content').val();


	   Plugins.waitTips({title:'信息提示',content:'正在提交数据，请稍后...'});
		$.post("{:U('Admin/WxPassiveReply/newsEdit')}",params,function(data,textStatus){
			var json = WST.toJson(data);
			if(json.status=='1'){
				Plugins.setWaitTipsMsg({ content:'操作成功',timeout:1000,callback:function(){
				   location.href="{:U('Admin/WxPassiveReply/news')}";
				}});
			}else{
				Plugins.closeWindow();
				Plugins.Tips({title:'信息提示',icon:'error',content:'操作失败!',timeout:1000});
			}
		});
   }
   </script>
   <body class="wst-page">
       <form name="myform" method="post" id="myform" autocomplete="off">
        <input type='hidden' id='id' value='{$object.id}'/>
        <table class="table table-hover table-striped table-bordered wst-form">
           <tr>
             <th width='120' align='right'>关键字<font color='red'>*</font>：</th>
             <td><input type='text' id='keyword' class="form-control wst-ipt" value='{$object.keyword}' maxLength='50'/></td>
           </tr>
           <tr>
             <th width='120' align='right'>标题<font color='red'>*</font>：</th>
             <td><input type='text' id='title' class="form-control wst-ipt" value='{$object.title}' maxLength='50'/></td>
           </tr>
           <tr>
             <th width='120' align='right'>描述<font color='red'>*</font>：</th>
             <td><input type='text' id='description' class="form-control wst-ipt" value='{$object.description}' maxLength='50'/></td>
           </tr>
           <tr>
             <th width='120' align='right'>封面图片<font color='red'>*</font>：</th>
             <td>
                <div>
                  <div id="filePicker" style='margin-left:0px;float:left'>上传图片</div>
                    <div style='margin-left:5px;float:left'>格式为 gif, jpg, jpeg, png</div>
                </div>
             </td>
           </tr>
           <tr>
             <th width='120' align='right'>封面图片预览<font color='red'> </font>：</th>
             <td>
                <div style="min-height:75px;min-width: 75px;">  
                  <?php if($object['picUrl']!=''){?>
                     <img style="max-height:75px;" src="<?php echo $object['picUrl']?>" id="preview" class="wst-ipt">
                     <input type="hidden" id="picUrl" value="<?php echo $object['picUrl']?>" />
                  <?php }else{ ?>
                     <img style="max-height:75px;" src="" id="preview" style="display: none;" class="wst-ipt">
                     <input type="hidden" id="picUrl" />
                  <?php }?>
                </div>
                
             </td>
           </tr>

           <tr>
             <th width='120' align='right'>回复内容<font color='red'>*</font>：</th>
             <td>
                  <textarea id="content" class="wst-ipt" style="width:350px;height:100px;">{$object.content}</textarea>
             </td>
           </tr>
           <tr>
             <th width='120' align='right'>图文链接<font color='red'>*</font>：</th>
             <td><input type='text' id='url' class="form-control wst-ipt" value='{$object.url}' maxLength='50'/></td>
           </tr>

           <tr>
             <td colspan='2' style='padding-left:250px;'>
                 <button type="submit" class="btn btn-success">保&nbsp;存</button>
                 <button type="button" class="btn btn-primary" onclick='javascript:location.href="{:U('Admin/WxPassiveReply/news')}"'>返&nbsp;回</button>
             </td>
           </tr>
        </table>
       </form>
   </body>
</html>